package com.gitee.wsl.collections.list

import androidx.collection.MutableObjectList
import androidx.collection.ObjectList


/**
 * @return a read-only [ObjectList] with nothing in it.
 */
fun<E>  Lists.emptyObjectList(): ObjectList<E> = androidx.collection.emptyObjectList()

/**
 * @return a read-only [ObjectList] with nothing in it.
 */
fun<E>  Lists.objectListOf(): ObjectList<E> = androidx.collection.objectListOf()

/**
 * @return a new read-only [ObjectList] with [element1] as the only element in the list.
 */
fun<E>  Lists.objectListOf(element1: E): ObjectList<E> = mutableObjectListOf(element1)

/**
 * @return a new read-only [ObjectList] with 2 elements, [element1] and [element2], in order.
 */
fun<E>  Lists.objectListOf(element1: E, element2: E): ObjectList<E> =
    mutableObjectListOf(element1, element2)

/**
 * @return a new read-only [ObjectList] with 3 elements, [element1], [element2], and [element3],
 * in order.
 */
fun<E>  Lists.objectListOf(element1: E, element2: E, element3: E): ObjectList<E> =
    mutableObjectListOf(element1, element2, element3)

/**
 * @return a new read-only [ObjectList] with [elements] in order.
 */
fun<E>  Lists.objectListOf(vararg elements: E): ObjectList<E> =
    MutableObjectList<E>(elements.size).apply { plusAssign(elements as Array<E>) }

/**
 * @return a new empty [MutableObjectList] with the default capacity.
 */
fun<E>  Lists.mutableObjectListOf(): MutableObjectList<E> = MutableObjectList()

/**
 * @return a new [MutableObjectList] with [element1] as the only element in the list.
 */
fun<E>  Lists.mutableObjectListOf(element1: E): MutableObjectList<E> {
    val list = MutableObjectList<E>(1)
    list += element1
    return list
}

/**
 * @return a new [MutableObjectList] with 2 elements, [element1] and [element2], in order.
 */
fun<E>  Lists.mutableObjectListOf(element1: E, element2: E): MutableObjectList<E> {
    val list = MutableObjectList<E>(2)
    list += element1
    list += element2
    return list
}

/**
 * @return a new [MutableObjectList] with 3 elements, [element1], [element2], and [element3],
 * in order.
 */
fun<E>  Lists.mutableObjectListOf(element1: E, element2: E, element3: E): MutableObjectList<E> {
    val list = MutableObjectList<E>(3)
    list += element1
    list += element2
    list += element3
    return list
}

/**
 * @return a new [MutableObjectList] with the given elements, in order.
 */
fun<E>  Lists.mutableObjectListOf(vararg elements: E): MutableObjectList<E> =
    MutableObjectList<E>(elements.size).apply { plusAssign(elements as Array<E>) }
